package getsmart.project.activity;

import java.util.ArrayList;

import getsmart.project.R;
import getsmart.project.database.DBProfil;
import getsmart.project.database.DBStudyType;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
import android.content.Intent;

public class ChooseKelas extends Activity {
	Button kelas1;
	Button kelas2;
	Button kelas3;
	Button kelas4;
	Button kelas5;
	Button kelas6;
	DBStudyType dbPelajaran;
	DBProfil prof;
	public static int kelasSiswa = 0;
	private static void getKelasSiswa(int Class) {
		ChooseKelas.kelasSiswa = Class;
	}

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.choose_class);
		dbPelajaran = new DBStudyType(this);
		prof = new DBProfil(this);
		kelas1 = (Button) findViewById(R.id.btn_kelas1_sd);
		kelas1.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				kelasSiswa = 1;
				if (kelasSiswa == 1) {
					tambahProfile(kelasSiswa);
					Intent i = new Intent(ChooseKelas.this, ListProfil.class);
					startActivity(i);
				}

			}
		});
		kelas2 = (Button) findViewById(R.id.btn_kelas2_sd);
		kelas2.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				kelasSiswa = 2;
				if (kelasSiswa == 2) {
					tambahProfile(kelasSiswa);
					Intent i = new Intent(ChooseKelas.this, ListProfil.class);
					startActivity(i);
				}
			}
		});
		kelas3 = (Button) findViewById(R.id.btn_kelas3_sd);
		kelas3.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				kelasSiswa = 3;
				if (kelasSiswa == 3) {
					tambahProfile(kelasSiswa);
					Intent i = new Intent(ChooseKelas.this, ListProfil.class);
					startActivity(i);
				}
			}
		});
		kelas4 = (Button) findViewById(R.id.btn_kelas4_sd);
		kelas4.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				kelasSiswa = 4;
				if (kelasSiswa == 4) {
					tambahProfile(kelasSiswa);
					Intent i = new Intent(ChooseKelas.this, ListProfil.class);
					startActivity(i);
				}
			}
		});
		kelas5 = (Button) findViewById(R.id.btn_kelas5_sd);
		kelas5.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				kelasSiswa = 5;
				if (kelasSiswa == 5) {
					tambahProfile(kelasSiswa);
					Intent i = new Intent(ChooseKelas.this, ListProfil.class);
					startActivity(i);
				}
			}
		});
		kelas6 = (Button) findViewById(R.id.btn_kelas6_sd);
		kelas6.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				kelasSiswa = 6;
				if (kelasSiswa == 6) {
					tambahProfile(kelasSiswa);
					Intent i = new Intent(ChooseKelas.this, ListProfil.class);
					startActivity(i);
				}
			}
		});
	}

	protected void tambahProfile(int kelas) {
		try {
			prof.addProfile(AddProfil.namaProfil, kelasSiswa);
			Toast.makeText(getBaseContext(),
					AddProfil.namaProfil + ", berhasil ditambahkan",
					Toast.LENGTH_SHORT).show();
			ArrayList<ArrayList<Object>> data = prof.getProfile();
			
		} catch (Exception e) {
			e.printStackTrace();
			Toast.makeText(getBaseContext(), "gagal simpan, " + e.toString(),
					Toast.LENGTH_LONG).show();
		}
	}
}
